home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / 3dvect37.zip / FILE.ASM < prev    next >
Assembly Source File  |  1994-06-22  |  17KB  |  694 lines

  1. ; this code belongs to TRAN
  2.  
  3.   OPENFILE              = 1
  4.   READFILE              = 1
  5.   WRITEFILE             = 1
  6.   LSEEKFILE             = 1
  7.   CREATEFILE            = 1
  8.   FILESIZE              = 1
  9.   FILECOPY              = 1
  10.   DELETEFILE            = 1
  11.   FINDFILE              = 1
  12.   ENVIRONMENT           = 1
  13.   FINDMARKER            = 1
  14.  
  15.         .386p
  16.         jumps
  17. code32  segment para public use32
  18.         assume cs:code32, ds:code32
  19.  
  20. include pmode.ext
  21. include macros.inc
  22.  
  23. public  _filebufloc, _filebuflen
  24. public  _closefile
  25.  
  26. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  27. ; DATA
  28. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  29. _filebufloc     dd      0               ; location must be in low mem
  30. _filebuflen     dw      4000h
  31.  
  32. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  33. ; CODE
  34. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  35.  
  36. ifdef   CREATEFILE
  37. public  _createfile
  38. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  39. ; Create file
  40. ; In:
  41. ;   EDX -> ASCIIZ filename
  42. ; Out:
  43. ;   CF=1 - Error creating file
  44. ;   CF=0 - File created succesfully
  45. ;     V86R_BX - file handle
  46. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  47. _createfile:
  48.         push ax
  49.         push edx
  50.         add edx,_code32a
  51.         mov ax,dx
  52.         shr edx,4
  53.         and ax,0fh
  54.         mov v86r_dx,ax
  55.         mov v86r_ds,dx
  56.         mov v86r_ax,3c00h
  57.         mov v86r_cx,20h
  58.         mov al,21h
  59.         int 33h
  60.         mov ax,v86r_ax
  61.         mov v86r_bx,ax
  62.         pop edx
  63.         pop ax
  64.         ret
  65. endif
  66.  
  67. ifdef   OPENFILE
  68. public  _openfile
  69. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  70. ; Open file
  71. ; In:
  72. ;   EDX -> ASCIIZ filename
  73. ; Out:
  74. ;   CF=1 - Error opening file
  75. ;   CF=0 - File opened succesfully
  76. ;     V86R_BX - file handle
  77. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  78. _openfile:
  79.         push ax
  80.         push edx
  81.         add edx,_code32a
  82.         mov ax,dx
  83.         shr edx,4
  84.         and ax,0fh
  85.         mov v86r_dx,ax
  86.         mov v86r_ds,dx
  87.         mov v86r_ax,3d02h
  88.         mov al,21h
  89.         int 33h
  90.         mov ax,v86r_ax
  91.         mov v86r_bx,ax
  92.         pop edx
  93.         pop ax
  94.         ret
  95. endif
  96.  
  97. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  98. ; Close a file
  99. ; In:
  100. ;   V86R_BX - file handle
  101. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  102. _closefile:
  103.         push ax
  104.         mov v86r_ax,3e00h
  105.         mov al,21h
  106.         int 33h
  107.         pop ax
  108.         ret
  109.  
  110. ifdef   DELETEFILE
  111. public  _deletefile
  112. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  113. ; Delete a file
  114. ; In:
  115. ;   EDX -> ASCIIZ filename
  116. ; Out:
  117. ;   CF=1 - Error opening file
  118. ;   CF=0 - File opened succesfully
  119. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  120. _deletefile:
  121.         push ax
  122.         push edx
  123.         add edx,_code32a
  124.         mov ax,dx
  125.         shr edx,4
  126.         and ax,0fh
  127.         mov v86r_dx,ax
  128.         mov v86r_ds,dx
  129.         mov v86r_ah,41h
  130.         mov al,21h
  131.         int 33h
  132.         pop edx
  133.         pop ax
  134.         ret
  135. endif
  136.  
  137. ifdef   LSEEKFILE
  138. public  _lseekfile
  139. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  140. ; Seek position in file
  141. ; In:
  142. ;   V86R_BX - file handle
  143. ;   EAX - signed offset to move to
  144. ;   BL - from: 0-beginning of file, 1-current location, 2-end of file
  145. ; Out:
  146. ;   CF=1  - Error seeking in file
  147. ;     EAX - ?
  148. ;   CF=0  - Seek fine
  149. ;     EAX - new offset from beginning of file
  150. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  151. _lseekfile:
  152.         mov v86r_ah,42h
  153.         mov v86r_al,bl
  154.         mov v86r_dx,ax
  155.         shr eax,16
  156.         mov v86r_cx,ax
  157.         mov al,21h
  158.         int 33h
  159.         pushf
  160.         mov ax,v86r_dx
  161.         shl eax,16
  162.         mov ax,v86r_ax
  163.         popf
  164.         ret
  165. endif
  166.  
  167. ifdef   FILESIZE
  168. public  _filesize
  169. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  170. ; Get size of file
  171. ; In:
  172. ;   V86R_BX - file handle
  173. ; Out:
  174. ;   CF=1  - Error checking file
  175. ;     EAX - ?
  176. ;   CF=0  - chek fine
  177. ;     EAX - size of file
  178. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  179. _filesize:
  180.         mov v86r_ax,4201h
  181.         xor eax,eax
  182.         mov v86r_cx,ax
  183.         mov v86r_dx,ax
  184.         mov al,21h
  185.         int 33h
  186.         push v86r_dx
  187.         push v86r_ax
  188.         mov v86r_ax,4202h
  189.         xor eax,eax
  190.         mov v86r_cx,ax
  191.         mov v86r_dx,ax
  192.         mov al,21h
  193.         int 33h
  194.         mov ax,v86r_dx
  195.         shl eax,16
  196.         mov ax,v86r_ax
  197.         pop v86r_dx
  198.         pop v86r_cx
  199.         mov v86r_ax,4200h
  200.         push eax
  201.         mov al,21h
  202.         int 33h
  203.         pop eax
  204.         ret
  205. endif
  206.  
  207. ifdef   READFILE
  208. public  _readfile
  209. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  210. ; Read from file
  211. ; In:
  212. ;   V86R_BX - file handle
  213. ;   EDX -> buffer to read to
  214. ;   ECX - number of bytes to read
  215. ; Out:
  216. ;   CF=1 - Error reading file
  217. ;     EAX - ?
  218. ;   CF=0 - Read went fine
  219. ;     EAX - number of bytes read
  220. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  221. _readfile:
  222.         pushad
  223.         xor ebp,ebp
  224.         add edx,_code32a
  225.         lea ebx,[ecx+edx]
  226.         cmp ebx,100000h
  227.         ja readlong
  228.         mov eax,edx
  229.         shr eax,4
  230.         and dx,0fh
  231.         mov v86r_ds,ax
  232.         mov v86r_dx,dx
  233. readl:
  234.         mov eax,0fff0h
  235.         cmp eax,ecx
  236.         jbe readlf1
  237.         mov eax,ecx
  238. readlf1:
  239.         mov v86r_cx,ax
  240.         mov v86r_ax,3f00h
  241.         mov al,21h
  242.         int 33h
  243.         jc readdone2
  244.         movzx ebx,v86r_ax
  245.         add ebp,ebx
  246.         sub ecx,ebx
  247.         jbe readdone
  248.         or ebx,ebx
  249.         jz readdone
  250.         add v86r_ds,0fffh
  251.         jmp readl
  252. readlong:
  253.         mov edi,edx
  254.         sub edi,_code32a
  255.         mov edx,ecx
  256.         mov eax,_filebufloc
  257.         add eax,_code32a
  258.         mov ebx,eax
  259.         shr eax,4
  260.         and bx,0fh
  261.         mov v86r_ds,ax
  262.         mov v86r_dx,bx
  263.         movzx ebx,_filebuflen
  264. readlongl:
  265.         mov eax,ebx
  266.         cmp eax,edx
  267.         jbe readlonglf1
  268.         mov eax,edx
  269. readlonglf1:
  270.         mov v86r_cx,ax
  271.         mov v86r_ax,3f00h
  272.         mov al,21h
  273.         int 33h
  274.         jc short readdone2
  275.         movzx ecx,v86r_ax
  276.         add ebp,ecx
  277.         mov eax,ecx
  278.         or eax,eax
  279.         jz readdone
  280.         mov esi,_filebufloc
  281.         rep movsb
  282.         sub edx,eax
  283.         ja readlongl
  284. readdone:
  285.         clc
  286. readdone2:
  287.         mov [esp+28],ebp
  288.         popad
  289.         ret
  290. endif
  291.  
  292. ifdef   WRITEFILE
  293. public  _writefile
  294. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  295. ; Write to file
  296. ; In:
  297. ;   V86R_BX - file handle
  298. ;   EDX -> buffer to write from
  299. ;   ECX - number of bytes to write
  300. ; Out:
  301. ;   CF=1 - Error writing file
  302. ;     EAX - ?
  303. ;   CF=0 - Write went fine
  304. ;     EAX - number of bytes read
  305. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  306. _writefile:
  307.         pushad
  308.         xor ebp,ebp
  309.         add edx,_code32a
  310.         lea ebx,[ecx+edx]
  311.         cmp ebx,100000h
  312.         ja writelong
  313.         mov eax,edx
  314.         shr edx,4
  315.         and ax,0fh
  316.         mov v86r_ds,dx
  317.         mov v86r_dx,ax
  318. writel:
  319.         mov eax,0fff0h
  320.         cmp eax,ecx
  321.         jbe writelf1
  322.         mov eax,ecx
  323. writelf1:
  324.         mov v86r_cx,ax
  325.         mov v86r_ax,4000h
  326.         mov al,21h
  327.         int 33h
  328.         jc writedone2
  329.         movzx ebx,v86r_ax
  330.         add ebp,ebx
  331.         sub ecx,ebx
  332.         jbe writedone
  333.         add v86r_ds,0fffh
  334.         jmp writel
  335. writelong:
  336.         mov esi,edx
  337.         sub esi,_code32a
  338.         mov edx,ecx
  339.         mov eax,_filebufloc
  340.         add eax,_code32a
  341.         mov ebx,eax
  342.         shr eax,4
  343.         and bx,0fh
  344.         mov v86r_ds,ax
  345.         mov v86r_dx,bx
  346.         movzx ebx,_filebuflen
  347. writelongl:
  348.         mov eax,ebx
  349.         cmp eax,edx
  350.         jbe writelonglf1
  351.         mov eax,edx
  352. writelonglf1:
  353.         mov ecx,eax
  354.         mov edi,_filebufloc
  355.         rep movsb
  356.         mov v86r_cx,ax
  357.         mov v86r_ax,4000h
  358.         mov al,21h
  359.         int 33h
  360.         jc writedone2
  361.         movzx ecx,v86r_ax
  362.         add ebp,ecx
  363.         sub edx,ecx
  364.         ja writelongl
  365. writedone:
  366.         clc
  367. writedone2:
  368.         mov [esp+28],ebp
  369.         popad
  370.         ret
  371. endif
  372.  
  373. ifdef   FILECOPY
  374. public  _filecopy
  375. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  376. ; Copy some bytes from one file to another
  377. ; In:
  378. ;   V86R_SI - source file handle
  379. ;   V86R_DI - destination file handle
  380. ;   ECX - number of bytes to copy
  381. ; Out:
  382. ;   CF=1  - Error copying file
  383. ;     EAX - ?
  384. ;   CF=0  - copied fine
  385. ;     EAX - number of bytes copied
  386. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  387. _filecopy:
  388.         pushad
  389.         xor ebp,ebp
  390.         mov edx,_filebufloc
  391.         add edx,_code32a
  392.         mov al,dl
  393.         and ax,0fh
  394.         shr edx,4
  395.         mov v86r_ds,dx
  396.         mov v86r_dx,ax
  397.         movzx ebx,_filebuflen
  398. copylongl:
  399.         mov eax,ebx
  400.         cmp eax,ecx
  401.         jbe copylonglf1
  402.         mov eax,ecx
  403. copylonglf1:
  404.         mov v86r_cx,ax
  405.         mov v86r_ax,3f00h
  406.         mov ax,v86r_si
  407.         mov v86r_bx,ax
  408.         mov al,21h
  409.         int 33h
  410.         jc copydone2
  411.         mov ax,v86r_ax
  412.         or ax,ax
  413.         jz copydone
  414.         mov v86r_cx,ax
  415.         mov v86r_ax,4000h
  416.         mov ax,v86r_di
  417.         mov v86r_bx,ax
  418.         mov al,21h
  419.         int 33h
  420.         jc copydone2
  421.         movzx edx,v86r_ax
  422.         add ebp,edx
  423.         sub ecx,edx
  424.         ja copylongl
  425. copydone:
  426.         clc
  427. copydone2:
  428.         mov [esp+28],ebp
  429.         popad
  430.         ret
  431. endif
  432.  
  433. ifdef   FINDFILE
  434. public  _findfile
  435. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  436. ; Do an AH=4E findfirst
  437. ; In:
  438. ;   AL - type of search: 4E-first, 4F-next
  439. ;   CX - search attributes
  440. ;   EDX -> 13 byte buffer for filename found
  441. ;   EDI -> search mask
  442. ; Out:
  443. ;   CF=1 - file not found
  444. ;     [EDX] - ?
  445. ;   CF=0 - file found
  446. ;     [EDX] - filename
  447. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  448. _findfile:
  449.         push eax
  450.         push esi
  451.         push edi
  452.         add edi,_code32a
  453.         mov esi,edi
  454.         and esi,0fh
  455.         shr edi,4
  456.         mov v86r_ds,di
  457.         mov v86r_dx,si
  458.         mov v86r_ah,al
  459.         mov v86r_cx,cx
  460.         mov esi,_code16a
  461.         sub esi,62h
  462.         mov edi,edx
  463.         mov al,21h
  464.         int 33h
  465.         mov ax,gs
  466.         mov ds,ax
  467.         movsd
  468.         movsd
  469.         movsd
  470.         movsb
  471.         mov ax,es
  472.         mov ds,ax
  473.         pop edi
  474.         pop esi
  475.         pop eax
  476.         ret
  477. endif
  478.  
  479. ifdef   ENVIRONMENT
  480.         public setup_env
  481.         public localpath
  482.         public envirpath
  483.         public progname
  484.  
  485. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  486. ; Setup_env - get environment path, program name
  487. ; In:
  488. ;   null
  489. ; Out:
  490. ;   localpath
  491. ;   envirpath
  492. ;   progname
  493. ; Notes:
  494. ; The following routines are by Alan Illeman
  495. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  496. setup_env:
  497.  
  498.         push    esi edi
  499.         mov     edi, _pspa
  500.         sub     edi, _code32a
  501.         movzx   eax, word ptr [edi]+2Ch
  502.         @segoff2ptr edi, eax, 0
  503.  
  504.         mov     ecx, 32768
  505.         mov     al, 1
  506.         cld
  507.         repne   scasb
  508.         inc     edi
  509.         mov     esi, edi
  510.         mov     edi, offset envirpath
  511. envir1:
  512.         lodsb
  513.         stosb
  514.         cmp     al, '\'
  515.         jne     envir2
  516.         mov     ebx, esi
  517. envir2:
  518.         or      al, al
  519.         jnz     envir1
  520. ;--------------------------------------
  521. ; save program name
  522. ;--------------------------------------
  523.         mov     esi, ebx
  524.         mov     edi, offset progname
  525. envir3:
  526.         lodsb
  527.         stosb
  528.         or      al, al
  529.         jnz     envir3
  530.  
  531. ;--------------------------------------
  532. ; get local path
  533. ;--------------------------------------
  534.         mov     edi, offset localpath
  535.  
  536.         mov     v86r_ah, 19h              ; get current disk
  537.         mov     al, 21h                   ; doscall
  538.         int     33h
  539.         mov     al, v86r_al               ; 0=A, 1=B, 2=C, etc
  540.  
  541.         mov     dl, al
  542.         inc     dl
  543.         add     al, 'A'                   ; drive letter
  544.         stosb
  545.         mov     al, ':'                   ; colon
  546.         stosb
  547.         mov     al, '\'                   ; backslash
  548.         stosb
  549.  
  550.         @ptr2segoff edi, ebx, eax
  551.         mov     v86r_ds, bx
  552.         mov     v86r_si, ax
  553.  
  554.         mov     v86r_ah, 47h              ; get current directory
  555.         mov     v86r_dl, dl               ; DL = disk
  556.         mov     al, 21h                   ; doscall
  557.         int     33h
  558.  
  559.         cmp     byte ptr [edi], 0         ; no directory ?
  560.         je      local1                    ; yes, exit
  561.  
  562.         mov     edi, offset localpath
  563.         mov     ecx, 127
  564.         add     edi, ecx
  565.         xor     al, al
  566.         std
  567.         repe    scasb
  568.         cld
  569.         inc     edi
  570.         inc     edi
  571.  
  572.         mov     al, '\'                   ; final backslash
  573.         stosb
  574. local1:
  575.         xor     al, al                    ; null termination
  576.         stosb
  577.  
  578.         pop     edi esi
  579.         ret
  580.  
  581. ; this is what the above routine sets up for you:
  582.  
  583. localpath db 160 dup(0)  ; current directory with "\" and terminating 0, eg c:\dir\@
  584. envirpath db 160 dup(0)  ; directory where program is (along with program name) eg c:\dir\prog.exe@
  585. progname  db 16 dup(0)   ; program name with terminating 0  eg prog.exe@
  586.  
  587.         endif
  588.  
  589. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  590. ; Findmarker - Find "[MARKER]"+text+0 in file:
  591. ;
  592. ; In:
  593. ; ECX -> ASCIIZ marker text to find.  text is null terminated. max findbuflen characters
  594. ; EDX -> ASCIIZ filename
  595. ;
  596. ; Out:
  597. ;
  598. ; EAX = position in file where marker found (=position after marker, ready to load data)
  599. ;  CF=1  - Error seeking in file or marker not found
  600. ;  CF=0  - Seek fine
  601. ;
  602. ; eg:dw x,x,x,x,"[MARKER]databeginshere"
  603. ;    dw 0,0,0,0  <- eax will point to this position in file if you seek for "databeginshere",0
  604. ;
  605. ; I will use this to store all my data (mods, gifs etc...) at the end  of  the
  606. ; executable.  when the appropriate data is required, search the program  name
  607. ; for the mod or gif required.  This then returns a seek position to load that
  608. ; mod   or     gif    from.     After    assembling    the    main    program,
  609. ; copy /b yourprog.exe+marker.txt+data.dat  to concatenate the  data   to  the
  610. ; executable.  Where marker.txt = "[MARKER]thing" and you search for  "thing".
  611. ; eax will then point to where data.dat is in yourprog.exe
  612. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  613. ifdef   FINDMARKER
  614.  
  615.         public _findmarker
  616.  
  617. findbuflen equ 32 ; buffer length to define maximum search string size (/2)
  618.  
  619. _findmarker:
  620.  
  621.         pushad
  622.         call _openfile
  623.         jc ferror
  624.         popad
  625.         pushad
  626.  
  627.         mov esi,ecx
  628.         mov ecx,findbuflen
  629.         mov edi,offset lookfor
  630.         rep movsb        ; move text into buffer
  631.  
  632.         mov edx, offset findbuffer1
  633.         mov ecx, findbuflen*2
  634.         call _readfile
  635.         jc ferror
  636.  
  637.         xor esi,esi
  638.         xor edi,edi
  639.         xor ebp,ebp
  640.  
  641. scanloop:
  642.         mov al,search[esi]
  643.         or al,al
  644.         jz foundit
  645.         cmp findbuffer1[edi],al
  646.         je next
  647.         mov esi,-1
  648. next:
  649.         inc esi
  650.         inc edi
  651.         inc ebp
  652.         cmp edi,findbuflen
  653.         jne scanloop
  654.  
  655.         push esi
  656.         mov ecx,findbuflen
  657.         mov esi,offset findbuffer2
  658.         mov edi,offset findbuffer1
  659.         rep movsb
  660.         pop esi
  661.  
  662.         mov edx, offset findbuffer2
  663.         mov ecx,findbuflen
  664.         push ebp
  665.         call _readfile
  666.         pop ebp
  667.         jc ferror
  668.         cmp eax,0
  669.         stc
  670.         je ferror
  671.  
  672.         xor edi,edi
  673.         jmp scanloop
  674.  
  675. foundit:
  676.         mov [esp+28],ebp
  677.         clc
  678. ferror:
  679.         pushf
  680.         call _closefile
  681.         popf
  682.         popad
  683.         ret
  684.  
  685. search      db "[MARKER]"
  686. lookfor     db findbuflen dup (0)
  687. findbuffer1 db findbuflen dup (0)
  688. findbuffer2 db findbuflen dup (0)
  689.  
  690.         endif
  691.  
  692. code32  ends
  693.         end
  694.